﻿Option Strict On

Imports Microsoft.VisualBasic
Imports System.Data.OleDb

Public Class AuthenticationDAO
    Dim connStr As String = ConfigurationManager.ConnectionStrings("ungvarberg").ConnectionString

    Public Function CheckUsernameAndPassword(ByVal username As String, ByVal password As String) As Integer
        Dim id As Integer = 0
        Dim sql As String = "SELECT userID FROM [tblUser] WHERE Username = @u AND Password = @p"

        Dim connection As New OleDbConnection(connStr)

        Dim command As New OleDbCommand(sql, connection)

        command.Parameters.AddWithValue("@u", username)
        command.Parameters.AddWithValue("@p", password)


        Try
            connection.Open()
            Dim reader As OleDbDataReader = command.ExecuteReader()

            If reader.Read() Then
                id = CType(reader("UserID"), Integer)
            End If


        Catch ex As Exception
            Throw ex
        Finally
            connection.Close()
            connection.Dispose()
        End Try

        Return id
    End Function




End Class
